var status = -1;
var itemList = Array(Array(1082581, 50000), Array(1082555, 50000), Array(1082549, 15000), Array(1082548, 15000));
var selectedItem = -1;
var selectedCost = -1;

function start() {
    action(1, 0, 0)
}

function action(g, c, b) {
    if (g == 1) {
        status++
    } else {
        if (status >= 0) {
            cm.dispose();
            return
        }
        status--
    }
    if (status == 0) {
        var f = "#fUI/UIWindow2.img/Quest/quest_info/summary_icon/summary#\r\n#fUI/UIWindow2.img/QuestAlarm/BtQ/normal/0#亲爱的#r#h ##k您好，请选择您希望购买的道具：";
        for (var a = 0; a < itemList.length; a++) {
            f += "\r\n#L" + a + "##i" + itemList[a][0] + ":# #b#t" + itemList[a][0] + "##k   #r" + itemList[a][1] + "#k点卷#l"
        }
        cm.askMenu(f)
    } else {
        if (status == 1) {
            var e = itemList[b];
            if (e != null) {
                selectedItem = e[0];
                selectedCost = e[1];
                cm.askYesNo("您是否购买#i" + selectedItem + ":# #b#t" + selectedItem + "##k 需要 #r" + selectedCost + "#k 点卷？")
            } else {
                cm.sendOk("出现错误...");
                cm.dispose()
            }
        } else {
            if (status == 2) {
                if (selectedCost <= 0 || selectedItem <= 0) {
                    cm.sendOk("购买道具出现错误...");
                    cm.dispose();
                    return
                }
                if (cm.getPlayer().getCSPoints(1) >= selectedCost) {
                    var d = cm.gainGachaponItem(selectedItem, 1, "点卷商店", 3, true);
                    if (d != -1) {
                        cm.getPlayer().modifyCSPoints(1, -selectedCost);
                        cm.sendOk("恭喜您成功购买#i" + selectedItem + ":# #b#t" + selectedItem + "##k。")
                    } else {
                        cm.sendOk("购买失败，请您确认在背包所有栏目窗口中是否有一格以上的空间。")
                    }
                } else {
                    cm.sendOk("您没有那么多点卷。\r\n\r\n购买#i" + selectedItem + ":# #b#t" + selectedItem + "##k 需要 #r" + selectedCost + "#k 点卷。")
                }
                cm.dispose()
            }
        }
    }
};